/**
 * This file stores all functions which make AJAX calls to the server
 *
 * @author nicholas malacarne <nicholas.malacarne@gmail.com>
 */

// attempts to log an account into the app -nm
function logIn(){
    
    // request log in -nm
    $.ajax({
        
        type:       "POST",
        url:        "./php/app/app_login.php",
        data:       { email:    $( '#username' ).val() , 
                      password: hex_md5( $( '#password' ).val() ) }
    
    }).done( function( data ){ // account has been logged in -nm
        
        // data log -nm
        log( data );
        
        // reload page -nm
        window.location.reload();
    
    }).fail( function(){ // no account found etc -nm
        
        console.log( "ajax.lib.js::logIn::failed!" );
    });
    
} // end function -nm

// attempts to log an account out of the app -nm
function logOut(){
    
    // requests log out -nm
    $.ajax({
        
        type:       "POST",
        url:        "./php/app/app_logout.php"
    
    }).done( function( data ){
        
        // data log -nm
        log( data );
        
        // reload page -nm
        window.location.reload();
    
    }).fail( function(){
        
        log( "ajax.lib.js::logIn::failed!" );
    });
    
} // end function -nm